<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /*
      1. sum(n=4) return 4 + sum(3); sum(4) = 10
      2. sum(n=3) return 3 + sum(2); sum(3)=6
      3. sum(n=2) return 2 + sum(1); sum(2)=3
      4. sum(n=1) return 1 + sum(0); sum(1)=1
      5. sum(0)=0 return 0
      */
      // function sum(n) {
      //   if (n === 0) return 0;
      //   return n + sum(n - 1);
      // }
      function sum(n) {
        return ((1 + n) * n) / 2;
      }
      console.log(sum(100));
    </script>
  </body>
</html>
